import { createRouter, createWebHistory } from 'vue-router'
import store from '../store'

const routes = [
  {
    path: '/',
    component: ()=> import('@/views/center'),
    children:[
      {
        path: '/',
        name: 'index',
        component: ()=> import('@/views/publicity/index'),
      },{
        path: '/help',
        name: 'help',
        component: ()=> import('@/views/publicity/helpCenter'),
      },{
        path: '/about',
        name: 'about',
        component: ()=> import('@/views/publicity/aboutUs'),
      },{
        path: '/product',
        name: 'product',
        component: ()=> import('@/views/publicity/productDuce'),
      },{
        path: '/check',
        name: 'check',
        component: ()=> import('@/views/check'),
      },{
        path: '/account',
        name: 'account',
        component: ()=> import('@/views/account')
      }
    ]
  },{
    path: '/logout',
    redirect: to => {
      store.commit('logout')
    }
  },{
    path: '/:pathMatch(.*)*',
    name: '404',
    component: () => import ('@/views/404')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeResolve((to, from,next) => {
  next()
})

router.beforeEach((to,form,next)=>{
  store.dispatch('removeHttpRequestList')
  next()
})

export default router
